/*
 * (C) Copyright 2011
 * Marvell Inc, <www.marvell.com>
 *
 * SPDX-License-Identifier: GPL-2.0+
 */

#ifndef _I2C_H_
#define _I2C_H_

#include "lv_drv_conf.h"
#if USE_I2C
#include <stdint.h>
#include <stdlib.h>

#define HAVE_I2C_SPEED_T

typedef enum {
    I2C_SPEED_STANDARD = 0,         /* standard mode:    ~100kbit/s */
    I2C_SPEED_FAST,                 /* fast mode:         ~400kbit/sj */
    I2C_SPEED_HIGH,                 /* high speed mode:   ~3.4Mbit/s */
} i2c_speed_t;

#define I2C_MASTER_CI2C0    0
#define I2C_MASTER_CI2C1    1
#define I2C_MASTER_PI2C     2
#define I2C_MASTER_CI2C2    3
#define I2C_MASTER_CI2C3    4
#define I2C_MASTER_MAX      5

typedef unsigned i2c_t;

struct i2c_conf_t {
    i2c_speed_t speed;
};

void i2c_initialize(i2c_t dev);
int i2c_acquire(i2c_t dev);
int i2c_release(i2c_t dev);
int i2c_read_bytes(i2c_t dev, uint16_t address, void *data, size_t length, uint8_t flags);
int i2c_read_byte(i2c_t dev, uint16_t address, void *data, uint8_t flags);
int i2c_read_reg(i2c_t dev, uint16_t address, uint16_t reg, void *data, uint8_t flags);
int i2c_read_regs(i2c_t dev, uint16_t address, uint16_t reg,
                  void *data, size_t length, uint8_t flags);
int i2c_write_bytes(i2c_t dev, uint16_t address, const void *data, size_t length, uint8_t flags);
int i2c_write_byte(i2c_t dev, uint16_t address, uint8_t data, uint8_t flags);
int i2c_write_reg(i2c_t dev, uint16_t address, uint16_t reg, uint8_t data, uint8_t flags);
int i2c_write_regs(i2c_t dev, uint16_t address, uint16_t reg,
                   const void *data, size_t length, uint8_t flags);
int arom_pi2c_init(unsigned addr);
int arom_pi2c_read_reg(unsigned reg, unsigned char *pval);
int arom_pi2c_write_reg(unsigned reg, unsigned char val);

int i2c_write_regs16(i2c_t dev, uint16_t address, uint16_t reg,
                   const void *data, size_t length, uint8_t flags);
int i2c_read_regs16(i2c_t dev, uint16_t address, uint16_t reg,
                  void *data, size_t length, uint8_t flags);
#endif

#endif

